﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonTypeSystem
{
    public class Student : ICloneable, IComparable<Student>
    {
        public string FirstName
        {
            get;
            set;
        }

        public string SecondName
        {
            get;
            set;
        }

        public string LastName
        {
            get;
            set;
        }

        public string SSN
        {
            get;
            set;
        }

        public string PermanentAddress
        {
            get;
            set;
        }

        public string MobilePhone
        {
            get;
            set;
        }

        public string EMail
        {
            get;
            set;
        }

        public int Course
        {
            get;
            set;
        }

        public Speciality Speciality
        {
            get;
            set;
        }

        public University University
        {
            get;
            set;
        }

        public Faculty Faculty
        {
            get;
            set;
        }

        public override bool Equals(object obj)
        {
            Student studentToCompare = obj as Student;
            if (studentToCompare == null)
            {
                return false;
            }
            return this.FirstName.Equals(studentToCompare.FirstName) &&
                this.SecondName.Equals(studentToCompare.FirstName) &&
                this.LastName.Equals(studentToCompare.FirstName) &&
                this.SSN.Equals(studentToCompare.FirstName) &&
                this.PermanentAddress.Equals(studentToCompare.FirstName) &&
                this.MobilePhone.Equals(studentToCompare.FirstName) &&
                this.EMail.Equals(studentToCompare.FirstName) &&
                this.Course.Equals(studentToCompare.FirstName) &&
                this.Speciality.Equals(studentToCompare.FirstName) &&
                this.University.Equals(studentToCompare.FirstName) &&
                this.Faculty.Equals(studentToCompare.FirstName);
        }

        public override int GetHashCode()
        {
            return FirstName.GetHashCode() ^ SecondName.GetHashCode() ^ LastName.GetHashCode() ^ SSN.GetHashCode() ^ Course.GetHashCode();
        }

        public override string ToString()
        {
            return StringUtils.Append("{ ",
                string.Format("FirstName => {0}, ", this.FirstName),
                string.Format("SecondName => {0}, ", this.SecondName),
                string.Format("LastName => {0}, ", this.LastName),
                string.Format("SSN => {0}, ", this.SSN),
                string.Format("PermanentAddress => {0}, ", this.PermanentAddress),
                string.Format("MobilePhone => {0}, ", this.MobilePhone),
                string.Format("EMail => {0}, ", this.EMail),
                string.Format("Course => {0}, ", this.Course),
                string.Format("Speciality => {0}, ", this.Speciality),
                string.Format("University => {0}, ", this.University),
                string.Format("Faculty => {0}", this.Faculty),
                " }");
        }

        public static bool operator ==(Student student1, Student Student2)
        {
            return student1.Equals(Student2);
        }

        public static bool operator !=(Student student1, Student Student2)
        {
            return !student1.Equals(Student2);
        }

        public object Clone()
        {
            Student st = new Student();
            st.FirstName = this.FirstName;
            st.SecondName = this.SecondName;
            st.LastName = this.LastName;
            st.SSN = this.SSN;
            st.PermanentAddress = this.PermanentAddress;
            st.MobilePhone = this.MobilePhone;
            st.EMail = this.EMail;
            st.Course = this.Course;
            st.Speciality = this.Speciality;
            st.University = this.University;
            st.Faculty = this.Faculty;
            return st;
        }

        public int CompareTo(Student other)
        {
            int result = this.FirstName.CompareTo(other.FirstName);
            if (result != 0)
            {
                return result;
            }
            
            result = this.SecondName.CompareTo(other.SecondName);
            if (result != 0)
            {
                return result;
            }

            result = this.LastName.CompareTo(other.LastName);
            if (result != 0)
            {
                return result;
            }

            result = this.SSN.CompareTo(other.SSN);
            if (result != 0)
            {
                return result;
            }

            else return result;
        }
    }
}
